package VolatileTest;

import java.util.ArrayList;

public class Test {
    static boolean flag=true;

    public static void main(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        //放入数字
        for (int i = 0; i < 5; i++) {
            arrayList.add(i);
        }
        //取数字
        //1.通过for循环
        for (int i = 0; i < arrayList.size(); i++) {
            Integer k=arrayList.get(i);
            System.out.print(k+" ");
        }
        System.out.println("\n-----------------------");
        //2.通过foreach
        for (Integer i: arrayList) {
            System.out.print(i+" ");
        }

    }
    public static void main1(String[] args) throws InterruptedException {
        new Thread(()->{
            while(flag){
                System.out.println(flag);
            }
            System.out.println("线程结束");

        }).start();
        Thread.sleep(1000);
        flag=false;
        System.out.println("主线程结束");
    }
}
